home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir35 / 0_byte10.zip / 0-BYTE.C next >
C/C++ Source or Header  |  1993-11-26  |  2KB  |  87 lines

  1. /* 0-byte.c */
  2.  
  3. /*
  4.     DESCRIPTION:
  5.     Accepts a DIR listing from Standard Input, and produces a 0-byte
  6.     length file for each file listed in the DIR listing.
  7.  
  8.     Subidirectories are ignored.
  9.  
  10.     USAGE:
  11.  
  12.     DIR \target\subdirectory | 0-BYTE > capture.cap
  13.  
  14.     The 0-byte-length files will be created in the current subdirectory.
  15.     0-byte will not overwrite existing files. Check CAPTURE.CAP for
  16.     the names of duplicate files found.
  17.  
  18.     dap@kandy.com  11/26/93
  19. */
  20.  
  21. /*
  22.     HISTORY:
  23.     If you find a bug, report it. Otherwise it probably won't get fixed.
  24.  
  25.     11/26/93 v1.0 Initial release. First (and hopefully last) version.
  26. */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31.  
  32. main()
  33. {
  34.   FILE  *zerofile;
  35.   char  *k;
  36.   char  buf[512];
  37.   char  errbuf[1024];
  38.  
  39.   fprintf(stderr, "0-BYTE v1.0 <dap@kandy.com>\n");
  40.   fprintf(stderr, "Last compiled on %s at %s\n\n", __DATE__, __TIME__);
  41.  
  42.   while((fgets(buf, 511, stdin))!=NULL)
  43.   {
  44.     if((strstr(buf, "<DIR>"))!=NULL)
  45.       continue;
  46.  
  47.     *(buf+12)='\0';
  48.  
  49.     if(*buf==' ' || *buf=='\n')
  50.       continue;
  51.  
  52.     k=strchr(buf, ' ');
  53.     *k='.';
  54.  
  55.     k++;
  56.     while(*k==' ')
  57.       strcpy(k, k+1);
  58.  
  59.     if((k=strchr(buf, ' '))!=NULL)
  60.       *k='\0';
  61.  
  62.     if(!strcmp(buf, "...") || !strcmp(buf, ".."))
  63.       continue;
  64.  
  65.     if((zerofile=fopen(buf, "r"))!=NULL)
  66.     {
  67.       fputc(7, stderr);
  68.       printf("%s EXISTS and will not be overwritten!\n", buf);
  69.       fclose(zerofile);
  70.       continue;
  71.     }
  72.     fclose(zerofile);
  73.  
  74.     if((zerofile=fopen(buf, "w"))==NULL)
  75.     {
  76.       sprintf(errbuf, "ERROR: %c%c%c%s", (char)7, (char)7, (char)7, buf);
  77.       perror(errbuf);
  78.     }
  79.     else
  80.     {
  81.       printf("%s\n", buf);
  82.       fclose(zerofile);
  83.     }
  84.   }
  85.   exit(0);
  86. }
  87.